package com.gillion.tms.controller;

import com.gfa4j.mybatis.dao.pojo.Page;
import com.gillion.business.model.Student;
import com.gillion.tms.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Created by admin on 2016/10/24.
 */

@Controller
public class StudentController {

    @Autowired
    private StudentService studentService;


    @ResponseBody
    @RequestMapping(value = "/select",method=RequestMethod.GET)
    public Page findStudentRecords(Page page,String studentName){
        return  studentService.findStudentRecords(page,studentName);
    }

    @ResponseBody
    @RequestMapping(value = "/query/{id}",method=RequestMethod.GET)
    public Student findStudentById(@PathVariable("id") Long studentId){
        return studentService.selectStudentById(studentId);
    }
    @ResponseBody
    @RequestMapping(value = "/selectStudent",method=RequestMethod.GET)
    public List<Student> getStudentByName(String studentName,String studentNm){
        return studentService.getStudentByName(studentName,studentNm);
    }
    @ResponseBody
    @RequestMapping(value = "/insert" ,method = RequestMethod.POST)
    public Map<String ,Object> createStudent(@RequestBody Student student1){
        return studentService.createStudent(student1);
    }

    @ResponseBody
    @RequestMapping(value = "/delete/{id}",method = RequestMethod.DELETE)
    public int deleteStudent(@PathVariable("id")Long id){
        return studentService.deleteStudent(id);
    }

    @ResponseBody
    @RequestMapping(value = "/update",method = RequestMethod.PUT)
    public int updateStudent(@RequestBody Student student){
        student.setStudentId(Long.parseLong(""+student.getStudentId()+""));
        student.setStudentName(student.getStudentName());
        student.setStudentNm(student.getStudentNm());
        student.setAge(Long.parseLong(""+student.getAge()+""));
        return studentService.updateStudent(student);
    }
}
